package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.HotelComment;
import cn.wolfcode.trip.base.query.HotelQueryObject;
import cn.wolfcode.trip.base.service.IHotelCommentService;
import cn.wolfcode.trip.base.service.IHotelService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//酒店资源的控制器
@RestController
@RequestMapping("/hotels")
public class HotelController {
    @Autowired
    private IHotelService hotelService;
    @Autowired
    private IHotelCommentService hotelCommentService;


    /*
    获取所有酒店
    资源:/hotels
    动作:GET
    参数:
     */
    @GetMapping
    public Object queryHotels(HotelQueryObject qo) {

        return hotelService.query(qo);
    }
    /*
    根据id获取酒店
    资源:/hotels
    动作:GET
    参数:id=xx
     */
    @GetMapping("/{hotelId}")
    public Object queryHotelById(@PathVariable Long hotelId) {

        return hotelService.queryHotelById(hotelId);
    }

    /*
    根据酒店id获取房型列表
    资源:/hotels/detail/{hotelId}
    动作:GET
    参数:
     */
    @GetMapping("/detail/{hotelId}")
    public Object queryHotelDetails(@PathVariable Long hotelId) {

        return hotelService.queryHotelDetailByHotelId(hotelId);

    }
    /*
    根据酒店id获取该酒店下所有用户的评论
    资源:/hotels/comments/{hotelId}
    动作:GET
    参数:
     */
    @GetMapping("/comments/{hotelId}")
    public Object queryCommentByHotelId(@PathVariable Long hotelId) {

        return hotelCommentService.queryCommentByHotelId(hotelId);

    }
    /*
    根据酒店id插入评论
    资源:/hotels/{hotelId}/comments
    动作:GET
    参数:
     */
    @PostMapping("/{hotelId}/comments")
    public Object saveComment(HotelComment entity) {
        hotelCommentService.saveOrUpdate(entity);
        return new JSONResult();

    }





}
